Vue.component('one', {
    template: '#tmp1',
    mounted() {
        $(document).ready(function () {
            $("#one").addClass("aBorder");
        });
    },
    methods: {
        // 全部组件中的下架商品处理函数
        cancelGoods: function () {
            swal({
                title: "商品下架",
                text: "您确定要永久下架该商品吗？",
                buttons: ["取消", "确认"],
            })
                .then((flag) => {
                    if (flag) {
                        console.log("确认");
                    } else {
                        console.log("取消");
                    }
                });
        },
    },
    destroyed() {
        $("#one").removeClass("aBorder");
    },
});
Vue.component('two', {
    template: '#tmp2',
    mounted() {
        $(document).ready(function () {
            $("#two").addClass("aBorder");
        });
    },
    destroyed() {
        $("#two").removeClass("aBorder");
    },
});
Vue.component('three', {
    template: '#tmp3',
    mounted() {
        $(document).ready(function () {
            $("#three").addClass("aBorder");
        });
    },
    methods: {
        // 正在收购组件中的下架商品处理函数
        cancelGoods: function () {
            swal({
                title: "商品下架",
                text: "您确定要永久下架该商品吗？",
                buttons: ["取消", "确认"],
            })
                .then((flag) => {
                    if (flag) {
                        console.log("确认");
                    } else {
                        console.log("取消");
                    }
                });
        },
    },
    destroyed() {
        $("#three").removeClass("aBorder");
    },
});
Vue.component('four', {
    template: '#tmp4',
    mounted() {
        $(document).ready(function () {
            $("#four").addClass("aBorder");
        });
    },
    destroyed() {
        $("#four").removeClass("aBorder");
    },
});
Vue.component('five', {
    template: '#tmp5',
    mounted() {
        $(document).ready(function () {
            $("#five").addClass("aBorder");
        });
    },
    methods: {
        // 已下架组件中的删除商品处理函数
        deleteGoods: function () {
            swal({
                title: "商品删除",
                text: "您确定要永久删除该商品吗？",
                buttons: ["取消", "确认"],
            })
                .then((flag) => {
                    if (flag) {
                        console.log("确认");
                    } else {
                        console.log("取消");
                    }
                });
        },
    },
    destroyed() {
        $("#five").removeClass("aBorder");
    },
});
// var vm = new Vue({
//     el: "#app",
//     data: {
//         comName:"one",
//         now_mode:'',//0已下架 1 收购中  2未发布  3下架,all 全部
//         render_list:[],//渲染列表
//     },
//     methods: {
//         changeItem:function(mode){
//             this.now_mode = mode;
//         }
//     },
//     computed: {

//     },
// });
var vm = new Vue({
    el: "#app",
    data: {
        status: 'all',//订单状态,状态 all全部 0无作用 1 收购中  2未发布  ,xjz 下架中, yjx 已下架
        page: 1,//当前页数
        limit: 10,//限制条数
        render_list: [],
        isLoading: false,//上拉刷新时加载中
        myloadding: false,//切换时加载中
        list_loading: false,//上拉加载的加载中
        list_finished: false,//上拉加载完成,没有更多数据时
        lock: false,
        pay_money:'888888888',
        show_mask:false,
        tid:'',
        pwd:'',
        money:0,//支付金额
    },
    created: function () {
        this.init();
    },
    methods: {
        init: function () {
            this.open_lock();
            function suc() {
            }
            function err() {
            }
            this.get_list(suc, err);
        },
        // 选择顶部栏
        chooseTab: function (status) {
            this.status = status;
            var that = this;
            // 更新列表
            this.page = 1;
            this.render_list = [];
            this.myloadding = true;
            this.get_list(suc, err);
            app.toastLoading('加载中');
            function suc() {
                that.myloadding = false;
                that.list_finished = false;
                that.list_finished = false;
                app.toastClear();
            }
            function err() {
                that.myloadding = false;
                that.list_finished = false;
                that.list_finished = false;
                app.toastClear();
            }
            this.$forceUpdate();
        },
        // 获取列表
        get_list: function (suc, err) {
            var that = this;
            var data = {
                page: that.page,
                limit: that.limit,
            }
            if (that.status == 'all') {
                // 全部
                data.status = '0,1,2,3';
            }else if(that.status == 'yxj'){
                // 已下架
                data.close = 0;
            }else if(that.status == 'xjz'){
                //下架中
                data.close = 1;
            }else{
                data.status = that.status;
            }
            $.post(app.webUrl + '/view/api_card/lists', data, function (ret) {
                if (ret.code == '1') {
                    console.log(ret.data);
                    ret.data.forEach(function (item) {
                        that.render_list.push(item);
                    });
                    that.page++;
                    // 成功的回掉函数
                    if (typeof suc == 'function') {
                        suc(ret);
                    }
                }
                else if (ret.code == '0') {
                    // 无数据的回掉函数
                    if (suc) {
                        suc(ret)
                    }
                } else {
                    if (err) {
                        err(err);
                    }
                }
            }).fail(function (err) {
                console.log(err);
            })
        },
        // 下拉刷新
        onRefresh: function () {
            var that = this;
            that.lock = false;
            that.page = 1;
            that.render_list = [];
            this.get_list(suc, err);
            function suc() {
                vant.Toast('刷新成功');
                that.isLoading = false;
                that.list_finished = false;
                that.list_finished = false;
                that.open_lock();
            }
            function err() {
                vant.Toast('刷新失败');
                that.isLoading = false;
                that.list_finished = false;
                that.list_finished = false;
            }
        },
        // 上拉加载,jiaye
        onLoad: function () {
            var that = this;
            if (!that.lock) {
                that.list_loading = false;
                return;
            }
            this.get_list(suc, err);
            //
            function suc(ret) {
                // 加载状态结束
                that.list_loading = false;
                if (ret.code == "0") {
                    that.list_finished = true;
                }
            }
            //
            function err(ret) {
                // 加载状态结束
                that.list_loading = false;
            }
        },
        // 打开lock
        open_lock: function () {
            var that = this;
            // 设一个延迟
            setTimeout(function () {
                that.lock = true;
            }, 1000)
        },
        //跳转聊天
        link_msg: function (id) {
            window.location.href = "{:url('card/Message/yonghu')}?&id=" + id;
        },
        // 下架商品
        btn_xiajiaGoods: function (item) {
            var that = this;
            vant.Dialog.confirm({
                message: '确认下架?',
            }).then(function () {
               $.post(app.webUrl+'/view/api_card/buy_out',{id:item.id},function(ret){
                   console.log(ret)
                   if(ret.code == '1'){
                    vant.Toast('下架成功');
                    setTimeout(function(){
                        $('.aBorder').get(0).click();
                    },1500);
                   }else{
                       vant.Toast('下架失败')
                   }
               })
            }).catch(function () {
                // return;
            });
        },
        // 商品管理按钮,跳转到商品管理
        btn_goodsManage: function (item) {
            window.localStorage.setItem('goodsItem',JSON.stringify(item))
            window.location.href = "/view/my/shougou_goods_management.html";
        },
        // 订单管理按钮
        btn_orderManage: function (item) {
            window.location.href = "/view/my/dingdanxiangqing_gm.html"
        },
        //立即付款
        btn_pay:function(item){
            this.show_mask = true;
            this.tid = item.id;
            if(item.ensure==0){
                this.money=(item.num*item.amount)+{$config['post_fee']};
            }
            if(item.ensure==1){
                this.money=(item.num*item.amount)+{$config['post_fee']}+{$config['post_fee_sp']};
            }
            
        },
        // 关闭支付弹窗
        close_pay:function(){
            this.show_mask = false;
        },
        //立即支付
        ljzf: function () {
            document.getElementById("zhifu").disabled = true;
            this.pwd = $("input[name = 'password']").val();
            if (this.pwd.length != 6) {
              vant.Toast({ message: "请输入六位数的支付密码");
              return
            }
            console.log(vm.tid);
            $.ajax({
              url: app.webUrl + "/view/api_card/publish_pay",
              type: "POST",
              data: {
                tid:vm.tid,
                pwd:app.doublemd5(this.pwd)
              },
              success: function (ret) {
                document.getElementById("zhifu").disabled = false;
                console.log(ret);
                if (ret.code == '1') {
                  vant.Toast({ message: "支付成功");
  
                  setTimeout(function () {
                    window.location.href = '/view/publish/fbsgcg.html?&activityId=' +this.vm.tid;
                  }, 2000)
                }else{
                  vant.Toast({ message: ret.msg);
                }
              },
            });   
          },
          //删除
        btn_cancelGoods:function(item){
            var that = this;
            vant.Dialog.confirm({
                message: '确认删除商品?',
            }).then(function () {
               $.post(app.webUrl+'/view/api_card/buy_del',{id:item.id},function(ret){
                   console.log(ret)
                   if(ret.code == '1'){
                    vant.Toast('删除成功');
                    setTimeout(function(){
                        $('.aBorder').get(0).click();
                    },1500);
                   }else{
                       vant.Toast('删除失败')
                   }
               })
            }).catch(function () {
                // return;
            });
        }
    },
});

$(".password-div input").on("input", function (e) { //标签为password-div下的input添加oninput事件
    var number = 6;   //定义输入最大值
    var pw = $("input[name = 'password']").val(); //定义pw为name是password的input框的输入值
    var list = $(".password-div ul li");  //定义list是li
    for (var i = 0; i < number; i++) {    //for循环遍历将·放入li标签
      if (pw[i]) {
        $(list[i]).text("·");
      } else {
        $(list[i]).text("");
      };
    };
  });

  // 点击空白清空密码
  $(".password-div ul").click(function () {
    $("input[name = 'password']").val("");
    $("#password").focus();
    $(".password-div ul li").text("");
  });
